<?php
/**
 * Copyright (c) 2006, PORTALIER Julien
 *
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 *
 * @package      FeatherCMS
 * @subpackage   Components
 * @copyright    Copyright (c) 2006, Julien PORTALIER
 * @link         http://julien.portalier.com
 * @license      http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

class CloudHelper extends Helper
{
	function render(&$tags, $base_link='', $levels=7, $css_class='tag', $html_tag='span')
	{
		$cloud = array();
		
		if (!empty($tags))
		{
			$min = min($tags);
			$max = max($tags);
			
			foreach($tags as $tag => $counter)
			{
				$curr_level = intval(($levels * ($counter - ($min - 1))) / (($max - ($min - 1)) + 1)) + 1;
				$swap_level = ($levels + 1) - $curr_level;
				
				$content = $this->link(str_replace(' ', '&nbsp;', $tag), $base_link.urlencode($tag),
					array('title' => sprintf(ngettext('One occurence', '%d occurences', $counter), $counter))
				);
				
				array_push($cloud, $this->contentTag($html_tag, $content, array('class' => $css_class.$swap_level)));
			}
		}
		
		return implode(' ', $cloud);
	}
}
?>